#include<vector>
#include<algorithm>
using namespace std;
class Solution {
public:
    bool checkDynasty(vector<int>& places) {
        sort(places.begin(), places.end());
        int n = places.size();
        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            if (places[i] == 0)count++;
            else if (places[i + 1] - places[i]) {
                count -= places[i + 1] - places[i] - 1;
            }
            else return false;
        }
        return count >= 0;
    }
};